package com.yami.shop.personnft.platform.controller;


import com.yami.shop.bean.model.PersonnftTansferEnpand;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.personnft.common.service.NftTansferEnpandService;
import com.yami.shop.personnft.common.vo.PersonnftTansferEnpandListDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 品牌信息
 *
 * @author FrozenWatermelon
 * @date 2020-10-28 15:27:24
 */
@RestController("adminNftTansferEnpandController")
@RequestMapping("/admin/productTansferEnpand")
@Tag(name = "admin-品类映射")
public class NftTansferEnpandController {

    @Autowired
    private NftTansferEnpandService nftTansferEnpandService;

    @GetMapping("getNftTansferEnpandList")
    @Operation(summary =  "获取映射List")
   public ServerResponseEntity<PageVO<PersonnftTansferEnpandListDto>> getNftTansferEnpandList(@Valid PageDTO pageDTO, PersonnftTansferEnpandListDto nftTansferEnpandListDto) {
        return ServerResponseEntity.success(nftTansferEnpandService.getNftTansferEnpandList(pageDTO, nftTansferEnpandListDto));
    }
    @GetMapping("getById")
    @Operation(summary =  "getById")
    public ServerResponseEntity<PersonnftTansferEnpand> getById(String id) {
        return ServerResponseEntity.success(nftTansferEnpandService.getById(id));
    }
    @PostMapping
    @Operation(summary =  "保存映射信息", description = "保存映射信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody PersonnftTansferEnpand nftTansferEnpand) {
        if (StringUtils.isEmpty(nftTansferEnpand.getVarietyCode())) {
            throw new YamiShopBindException("yami.sys.illegalArgument");
        }
        if (nftTansferEnpand.getProdId()==null) {
            throw new YamiShopBindException("yami.sys.illegalArgument");
        }
        nftTansferEnpandService.insertSelective(nftTansferEnpand);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary =  "更新映射信息", description = "更新映射信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody PersonnftTansferEnpand productTansferEnpand) {
        if (productTansferEnpand.getId()==null) {
            throw new YamiShopBindException("yami.sys.illegalArgument");
        }
        nftTansferEnpandService.update(productTansferEnpand);
        return  ServerResponseEntity.success();
    }

    @GetMapping("/delete")
    @Operation(summary =  "删除映射信息", description = "根据映射信息id删除映射信息")
    public ServerResponseEntity<Void> delete(String id) {
        nftTansferEnpandService.deleteById(id);
        return  ServerResponseEntity.success();
    }

}
